#include "Pch.h"

#include "../../MCD/Core/System/Path.h"
#include "../../MCD/Render/Mesh.h"

#include "../Fbx/FbxFile.h"
#include "../Fbx/ModelImporter.h"

#include "../Core/Application.h"

using namespace IS;

namespace TestModelImporter
{

class TestApp : public Application
{
public:
	ModelPtr mModel;

	TestApp()
		: Application( L"title=TestModelImporter;width=800;height=600;FSAA=1" )
	{
		mCamera.moveForward(-10.0f);

		// open fbx file
		std::wstring fbxfilepath = (Path::getCurrentPath() / L"media/CornellBox.fbx").getString();
		//std::wstring fbxfilepath = (Path::getCurrentPath() / L"media/scene02_cave_master.fbx").getString();

		Log::format( Log::Info, L"Importing %s ...", fbxfilepath.c_str() );

		FbxFile fbxfile(fbxfilepath.c_str());

		if(!fbxfile.open())
			return;

		Log::format( Log::Info, L"FBX file version %d.%d.%d"
			, fbxfile.fileVersion().major
			, fbxfile.fileVersion().minor
			, fbxfile.fileVersion().revision
			);

		// import triangle buffers
		mModel = new Model(fbxfilepath);
		ModelImporter().import(fbxfile, *mModel);
	}

	sal_override void update(float deltaTime)
	{
		// render the triangle buffers
		mModel->draw();
		/*
		for(Model::MeshAndMaterial* meshAndMat = mModel->mMeshes.begin(); meshAndMat != mModel->mMeshes.end(); meshAndMat = meshAndMat->next())
		{
			if(!meshAndMat->mesh)
				continue;

			glPushMatrix();
			meshAndMat->mesh->draw();
			glPopMatrix();
		}
		*/
	}

};	// class TestApp

}	// namespace TestModelImporter

TEST(TestModelImporter)
{
	TestModelImporter::TestApp app;
	app.mainLoop();
}